﻿using Microsoft.AspNetCore.Mvc;
using Model.BusinessModel;
using Utility;
using DomainService.IService.Sys;
using Model.DomainModel.Sys;
using Model.BusinessModel.OutPut.sys;
using Model.BusinessModel.OutPut;
using DomainService.Service.Sys;

namespace OverallAuth_WebApi.Controllers.Sys
{
    /// <summary>
    /// Sys_Button 按钮
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "SysButton")]
    public class SysButtonController : BaseController
    {
        #region 构造实列化

        /// <summary>
        /// 按钮服务
        /// </summary>
        public ISysButtonService _buttonService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="buttonService"></param>
        public SysButtonController(ISysButtonService buttonService)
        {
            _buttonService = buttonService;
        }

        #endregion

        #region 接口


        /// <summary>
        /// 新增按钮信息
        /// </summary>
        /// <param name="sysButton"></param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus Insert(SysButton sysButton)
        {
            sysButton.CreateTime = DateTime.Now;
            sysButton.CreateUser = GetLoginUserMsg().UserId.ToString();
            return _buttonService.Insert(sysButton);
        }

        /// <summary>
        /// 修改按钮信息
        /// </summary>
        /// <param name="sysButton"></param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus Update(SysButton sysButton)
        {
            sysButton.CreateTime = DateTime.Now;
            sysButton.CreateUser = GetLoginUserMsg().UserId.ToString();
            return _buttonService.Update(sysButton);
        }

        /// <summary>
        ///  获取按钮数据
        /// </summary>
        /// <param name="pageResultModel">分页模型</param>
        /// <returns>返回按钮数据</returns>
        [HttpPost]
        public ReceiveStatus<SysButtonDataOutPut> GetButtonList(PageResultModel pageResultModel)
        {
            ReceiveStatus<SysButtonDataOutPut> receiveStatus = new();
            var result = _buttonService.GetButtonList(pageResultModel);
            receiveStatus.data = result.data;
            receiveStatus.total = result.total;
            return receiveStatus;
        }

        /// <summary>
        /// 获取公司、系统、菜单、按钮关系数据
        /// </summary>
        /// <returns>返回公司、系统、菜单、按钮的上下级关系</returns>
        [HttpGet]
        public ReceiveStatus<TreeExtendOutPut<SysButtonDataOutPut>> GetAllButtonList()
        {
            return _buttonService.GetAllButtonList(GetLoginUserMsg().CorporationKey ?? string.Empty);
        }

        /// <summary>
        /// 获取公司下系统菜单按钮
        /// </summary>
        /// <param name="corporationKey">公司key</param>
        /// <param name="systemKey">系统key</param>
        /// <returns>返回系统、菜单、按钮的上下级关系</returns>
        [HttpGet]
        public ReceiveStatus<TreeExtendOutPut<SysButtonDataOutPut>> GetSystemMenuButtonList(string corporationKey, string systemKey)
        {
            return _buttonService.GetSystemMenuButtonList(corporationKey, systemKey);
        }

        /// <summary>
        /// 获取菜单按钮权限
        /// </summary>
        /// <param name="menuId">菜单key</param>
        /// <param name="buttonRoleType">按钮类型</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SysButtonDataOutPut> GetMenuButtonAuthList(string menuId, int buttonRoleType)
        {
            var loginUser = GetLoginUserMsg();
            return _buttonService.GetMenuButtonAuthList(loginUser.UserId ?? string.Empty, loginUser.CorporationKey ?? string.Empty, loginUser.SystemKey, menuId, buttonRoleType);
        }

        /// <summary>
        /// 获取菜单按钮
        /// </summary>
        /// <param name="menuId">菜单key</param>
        /// <param name="buttonRoleType">按钮类型</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SysButtonDataOutPut> GetMenuButtonList(string menuId, int buttonRoleType)
        {
            return _buttonService.GetMenuButtonList(menuId, buttonRoleType);
        }
        #endregion
    }
}
